<template>
	<view>
		<view>云函数</view>
		<button @click="callFunc">调用云函数</button>
		<button @click="callObj">调用云对象</button>
		<button @click="getUserAll">获取所有的用户数据</button>
		<button @click="addUser">新增用户</button>
		<button @click="getUserWithName">mongdb获取张三</button>
	</view>
</template>

<script lang="ts" setup>
	const cloudObj = uniCloud.importObject('codingguli-obj-one')

	const callFunc = async () => {
		const result = await uniCloud.callFunction({
			name: 'codingguli-func',
			data: {
				a: 1,
				b: 2
			}
		})
		console.log('查看结果', result);
	}

	const callObj = async () => {
		const result = await cloudObj.reduce(1, 2)
		console.log('查看一下', result);
	}

	const getUserAll = async () => {
		const result = await cloudObj.getUser()
		console.log('查看查询用户列表结果', result);
	}

	const addUser = async () => {
		const result = await cloudObj.addUser({
			"name": "刘梦晨",
			"birth_year": 2002,
			"tel": "13634567890",
			"email": "liumc@mail.com",
			"intro": "沟通能力强，团队合作佳"
		})
		console.log('查看新增用户结果', result);
	}
	
	const getUserWithName = async () => {
		const result = await cloudObj.getUser()
		console.log('拿到result', result);
	}
</script>